package com.czy.owner.adapter;

import android.content.Context;
import android.text.Html;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.entity.StrategyListModel;
import com.czy.owner.utils.TimeUtils;
import com.czy.owner.utils.glide.GlideUtils;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;

/**
 * Created by Administrator on 2017/5/15 0015.
 */

public class StrategyListAdapter extends RecyclerArrayAdapter<StrategyListModel>{
    private Context context;
    private String inforBaseName;
    public StrategyListAdapter(Context context,String inforBaseName) {
        super(context);
        this.context = context;
        this.inforBaseName = inforBaseName;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new StragegyViewHolder(parent);
    }
    class StragegyViewHolder extends BaseViewHolder<StrategyListModel>{
        private ImageView imgFindCarInformation;
        private TextView tvFindCarInfromationTitle;
        private TextView tvFindCarInfromationTime;
        private TextView tvFindCarInfromationRead;
        public StragegyViewHolder(ViewGroup parent) {
            super(parent, R.layout.item_carinformation);
            imgFindCarInformation = $(R.id.img_find_car_information);
            tvFindCarInfromationTitle = $(R.id.tv_find_car_infromation_title);
            tvFindCarInfromationTime = $(R.id.tv_find_car_infromation_time);
            tvFindCarInfromationRead = $(R.id.tv_find_car_infromation_read);
        }

        @Override
        public void setData(StrategyListModel data) {
            super.setData(data);
            String title = "<font color='#f4a624'>「"+inforBaseName+"」"+ "</font>"+data.getTitle();
            tvFindCarInfromationTitle.setText(Html.fromHtml(title));
            String mTime = TimeUtils.getTimeRange(TimeUtils.formatTimeDifference(data.getCreateTime()));
            if(mTime.substring(0,1).equals("-")){
                tvFindCarInfromationTime.setText(mTime.substring(1,mTime.length()));
            }else {
                tvFindCarInfromationTime.setText(mTime);
            }
            tvFindCarInfromationRead.setText(data.getViewCount()+"阅读");
            GlideUtils.loadImage(context, data.getCoverUrl(), imgFindCarInformation, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                @Override
                public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                }

                @Override
                public void onLoadingError(String source, Exception e) {

                }
            },R.mipmap.default_banner,R.mipmap.default_banner);
        }
    }
}
